from selenium.webdriver.common.by import By

from utils.page import Page


class PageSell(Page):
    """
    我的实验界面
    """
    url = 'http://120.53.243.26:8009/api/experiment/findPage'
    # 实验编号
    loc_experimentCode = (By.XPATH, '// *[ @ id = "basicSearch"] / div[1] / div[1] / div / input')
    # 实验状态
    loc_status = (By.XPATH, '//*[@id="basicSearch"]/div[1]/div[2]/span')
    # 实验类型
    loc_experimentType = (By.XPATH, '//*[@id="basicSearch"]/div[1]/div[3]/div/input')
    # 实验名称
    loc_experimentName = (By.XPATH, '//*[@id="basicSearch"]/div[1]/div[4]/div/input')
    # 搜索
    loc_search = (By.CLASS_NAME, 'el-icon-search')
    # 重置
    loc_reset = (By.CLASS_NAME, 'el-icon-delete')
    # 实验信息
    loc_table = (By.CLASS_NAME, 'el - table__body - wrapper is -scrolling - none')

    def __init__(self):
        super(PageSell, self).__init__()


    def input_experimentCode(self,experimentCode):
        """
        输入实验编号
        """
        self.input(self.loc_experimentCode, experimentCode)

    def input_status(self,status):
        """
        输入实验状态
        """
        self.input(self.loc_status, status)

    def input_experimentType(self,experimentType):
        """
        输入实验类型
        """
        self.input(self.loc_experimentType, experimentType)

    def input_experimentName(self,experimentName):
        """
        输入实验名称
        """
        self.input(self.loc_experimentName, experimentName)

    def click_search(self):
        """
        点击搜索
        """
        self.click(self.loc_search)

    def click_reset(self):
        """
        点击重置
        """
        self.click(self.loc_reset)

    def input_experiment(self,experimentCode,status,experimentType,experimentName):
        """
        输入实验信息
        """
        self.input(self.loc_experimentCode,experimentCode)
        self.input(self.loc_status,status)
        self.input(self.loc_experimentType,experimentType)
        self.input(self.loc_experimentName,experimentName)

    def search_experiment(self, experimentCode,status,experimentType,experimentName):
        """
        搜索实验
        """
        self.input_experimentCode(experimentCode)
        self.input_status(status)
        self.input_experimentType(experimentType)
        self.input_experimentName(experimentName)
        self.click_search()

    def reset_experiment(self, experimentCode,status,experimentType,experimentName):
        """
        实验重置
        """
        self.input_experimentCode(experimentCode)
        self.input_status(status)
        self.input_experimentType(experimentType)
        self.input_experimentName(experimentName)
        self.click_reset()

    @property
    def get_product_data(self):
        """
        获取实验信息
        """
        data = []
        trs = self.finds(self.loc_table)
        if trs is None:
            return data

        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            items = []
            for td in tds:
                items.append(td.text)
            data.append(items)
        return data

